enum KEYS {
    USER_DATA = 'userData',
    SITE_DATA = 'siteData',
    GUIDE = 'is_guide_operation',
    GUIDE_DATE = 'guide_date',
    CALLBACK_URL = 'callback_url',
    /** 求职档案来源 */
    ARCHIVE_DETAIL_SOURCE = 'archive_detail_source',
    /** 身份信息 1：学员；2：讲师 */
    IDENTITY_TYPE = 'identity_type',
    /** 编辑生涯彩虹图的数据 */
    RAINBOW_DATA = 'rainbow_data',
    /** 跳转url */
    SKIP_URL = 'skip_url',
    /**  选择的平台站点信息  */
    CHOOSE_PLATFORM_SITE = 'choose_platform_site',
}

/**
 * 获取 localStorage
 * @param key
 * @returns
 */
export const getLocalStorage = (key: keyof typeof KEYS) => {
    if (typeof window === 'undefined') return
    const res = localStorage.getItem(KEYS[key]) as any

    try {
        return JSON.parse(res)
    } catch (e) {
        return res
    }
}

/**
 * 通用写入 localStorage
 * @param key
 * @param val
 */
export const setLocalStorage = (key: keyof typeof KEYS, val: any) => {
    if (typeof window === 'undefined') return
    localStorage.setItem(KEYS[key], typeof val === 'object' ? JSON.stringify(val) : val)
}

/**
 * 删除
 * @param key
 */
export const delLocalStorage = (key: keyof typeof KEYS) => {
    if (!window) return
    localStorage.removeItem(key)
}
